package org.brisling.docManage.service;

import java.util.List;

import org.brisling.common.ConstSysParam;
import org.brisling.docManage.domain.Doctype;
import org.brisling.docManage.repository.DoctypeRepo;
import org.brisling.sysman.service.base.BaseSysmanTreeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
/**
 * 文档类型服務service
 * @Author : jackson wang
 * @Date   : 2015年6月8日 下午4:18:01
 * @version: 1.0
 */
@RestController
@RequestMapping("/doctype")
public class DoctypeService extends BaseSysmanTreeService<Doctype> {
	
	@SuppressWarnings("unused")
	@Autowired
	private DoctypeRepo baseRepo;

	
	public DoctypeService(){
		this.moduleName = ConstSysParam.MODULE_DOCTYPE;
		this.clazz = Doctype.class;
	}
	/* (non-Javadoc)
	 * @see org.brisling.service.sysman.DepartmentServiceInf#getMainPage()
	 */
	@RequestMapping("/mainPage.action")
	public ModelAndView getMainPage(){
		return new ModelAndView("/document/doctypeList");
	}
	
	/* (non-Javadoc)
	 * @see org.brisling.service.sysman.DepartmentServiceInf#getEditPage()
	 */
	@RequestMapping("/editPage.action")
	public ModelAndView getEditPage(){
		return this.getBizEditPage();
	}	
	
	
	/* (non-Javadoc)
	 * @see org.brisling.service.sysman.DepartmentServiceInf#getTreeNode(java.lang.Long)
	 */
	@RequestMapping("/getTree.action")
	public List<Doctype> getTreeNode(@RequestParam(value="id",required=false) Long id,
			@RequestParam(value="doccode",required=false) Long doccode,
			@RequestBody(required=false) String body){
		
		if(doccode!=null){
			return super.getRootNode(doccode);
		}else{
			return super.getNode(id);
		}
	}
	/* (non-Javadoc)
	 * @see org.brisling.service.sysman.DepartmentServiceInf#delDepartment(java.lang.Long)
	 */
	@RequestMapping("/del.action")
	public String delDepartment(@RequestParam(value="id",required=false) Long id){
		
		super.del(id);
		return "200";
	}
	
	/* (non-Javadoc)
	 * @see org.brisling.service.sysman.DepartmentServiceInf#save(java.lang.String)
	 */
	@RequestMapping("/save.action")
	public Doctype save(@RequestBody String body){
		Doctype obj = this.bodyToObj(body, Doctype.class);
		super.save(obj);
		return obj;
	}

}
